import type { App, Component } from 'vue'

/**
 * 为组件添加 withInstall 方法
 * @param component - 要安装的组件
 * @returns 返回带有 withInstall 方法的组件
 */
export function withInstall<T>(component: T) {
  ;(component as any).install = (app: App) => {
    const componentName = (component as any).name
    app.component(componentName, component as unknown as Component)
  }
  return component as T & Component
}
